package com.hc.server;

import org.json.JSONException;
import org.json.JSONObject;

public class Response {

	private JSONObject resp;
	private JSONObject respContent;

	private static final int SUCCESS = 0;
	private static final String SUCCESS_MSG = "成功！";
	
	private static final String ACTION_NAME = "ACTION_NAME";
	private static final String ACTION_INVOKER = "ACTION_INVOKER";
	private static final String ACTION_MODULE = "ACTION_MODULE";
	private static final String ACTION_RETURN_CODE = "ACTION_RETURN_CODE";
	private static final String ACTION_RETURN_MESSAGE = "ACTION_RETURN_MESSAGE";
	private static final String ACTION_INFO = "ACTION_INFO";

	public Response() {
		this.resp = new JSONObject();
		this.respContent = new JSONObject();
		try {
			resp.put(ACTION_INVOKER, "CTI");
			resp.put(ACTION_MODULE, "TRIPMALL");
			resp.put(ACTION_RETURN_CODE, SUCCESS);
			resp.put(ACTION_RETURN_MESSAGE, SUCCESS_MSG);
			resp.put(ACTION_INFO, respContent);
		} catch (JSONException e) {
		}
	}

	protected void setActionName(String actionName){
		try {
			resp.put(ACTION_NAME, actionName);
		}catch (JSONException e) {
		}
	}
	
	public void setErrResp(int errCode, String errMsg) {
		try {
			resp.put(ACTION_RETURN_CODE, errCode);
			resp.put(ACTION_RETURN_MESSAGE, errMsg);
		} catch (JSONException e) {
		}
	}

	public void appendRespContent(String key, int value) {
		try {
			respContent.put(key, value);
		} catch (JSONException e) {
		}
	}

	public void appendRespContent(String key, Object value) {
		try {
			respContent.put(key, value);
		} catch (JSONException e) {
		}
	}

	public String toString() {
		return resp.toString();
	}
}
